Skip to content

feat(pdo): add with-transaction macro#32

Merged
Chemaclass merged 1 commit into
mainfrom
feat/20-with-transaction
Jun 3, 2026
Merged

feat(pdo): add with-transaction macro#32
Chemaclass merged 1 commit into
mainfrom
feat/20-with-transaction

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

Adds the pdo/with-transaction macro so callers stop hand-writing the begin/try/commit/rollback dance:

(pdo/with-transaction conn
  (pdo/insert conn :accounts {:name "a" :balance 100})
  (pdo/insert conn :accounts {:name "b" :balance 0}))
;; commits + returns the last body value, or rolls back + re-throws on error

Semantics (per #20):

  • (begin conn) before the body; (commit conn) on normal completion; macro evaluates to the last body form.
  • On any \Throwable: (rollback conn) then re-throw the original.
  • Nesting: if (in-transaction conn) is already true, the body runs inline - no nested begin/commit (v1, no savepoints; documented).

Hygiene

conn is evaluated once into an auto-gensym conn#; result# / e# are gensym'd. Expansion calls begin/commit/rollback/in-transaction via syntax-quote qualification, so it resolves correctly from any caller namespace (proven by the tests living in phel.pdo-test).

  • Tests: commit-path + return value, rollback-on-throw + re-throw, and nested-inline (inner call leaves the outer transaction open; outer rollback reverts the inline write).
  • README transactions row + docs/recipes.md transactions section + CHANGELOG updated.

Polish pass: no refactor needed - single let/if/try form, no duplication.

composer test green (56 assertions).

Closes #20

@Chemaclass Chemaclass added the enhancement New feature or request label Jun 3, 2026
@Chemaclass Chemaclass self-assigned this Jun 3, 2026
@Chemaclass Chemaclass merged commit 01f9b1e into main Jun 3, 2026
1 check passed
@Chemaclass Chemaclass deleted the feat/20-with-transaction branch June 3, 2026 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: with-transaction macro (commit on success, rollback + re-throw on error)

1 participant